<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt"  uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title><spring:message code="member.shippingAddress"></spring:message></title>
    <link href="${pageContext.request.contextPath }/phone/css/font/iconfont.css" rel="stylesheet" type="text/css" />
    <!--公共样式-->
    <link href="${pageContext.request.contextPath }/phone/css/public.css" rel="stylesheet" type="text/css" />
    <!--layer弹出-->
    <link href="${pageContext.request.contextPath }/phone/js/layer/skin/layer.css" rel="stylesheet" type="text/css" />
    <!--我的(个人中心)样式-->
    <link href="${pageContext.request.contextPath }/phone/css/mine.css" rel="stylesheet" type="text/css" />

</head>
<body>
<!--头部 begin-->
<header class="page_topbar">
    <a href="${pageContext.request.contextPath }/api/member/userCenter" class="back Hui-iconfont"></a>
    <div class="title"><spring:message code="member.shippingAddress"></spring:message></div>
</header>
<!--头部 end-->
<div class="content" style="color:#000;">
    <ul class="adresslist">
     <c:forEach items="${addresslist}" var="item">
        <li>
            <div class="adressn"><span>${item.aName}</span><span>${item.aPhone}</span></div>
            <div class="adressn">${item.aAddress}${item.aAddressInfo}</div>
            <div class="adressbottom">
                <div class="adressbottomleft">
                <input type="radio"
                 <c:if test="${item.aDefault==1}">
                 checked="checked"
                 </c:if>
                 name="address" value="${item.aId}" /><spring:message code="reciveAddress.setAsDefault"></spring:message></div>
                <div class="adressbottomright"><span onclick="update(${item.aId})"><i class="Hui-iconfont">&#xe692;</i><spring:message code="reciveAddress.revise"></spring:message></span><span onclick="del(${item.aId});"><i class="Hui-iconfont">&#xe609;</i><spring:message code="reciveAddress.delete"></spring:message></span></div>
                <div class="clearf"></div>
            </div>
        </li>
       </c:forEach>
        
    </ul>
</div>
<div class="bottomaddress">
    <div class="block-auto"><a class="end-next" href="JavaScript:add()"><spring:message code="tianjiashouhuodizhi"></spring:message></a></div>
</div>
</body>
<script src="${pageContext.request.contextPath }/phone/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/lib/layer/layer_mobile/layer.js"></script>
<script>
    /*删除地址*/
   function del(id){
	   layer.open({
		    content: '<spring:message code="reciveAddress.confirmDeletion"></spring:message>'
		    ,btn: ['<spring:message code="reciveAddress.confirm"></spring:message>', '<spring:message code="reciveAddress.cancel"></spring:message>']
		    ,yes: function(index){
		    	 $.ajax({
	    			 url:'${pageContext.request.contextPath }/web/address/deladdress',
	    			 async : false,
	    			 data: {aId:id},
	    			 type : "POST", 
	    			 success :function(result){
	    			 var status=result.msg.status;
	    			 var desc=result.msg.desc;
	    			 if(status == 0){
	    				 layer.open({content: '<spring:message code="shanchuchenggong"></spring:message>',skin: 'msg',time: 1});
	  		   	   		
	    				 location.reload(true);
	    			 }else if(status == 2){//没登录
	    				 layer.open({content: '<spring:message code="weidenglu"></spring:message>',skin: 'msg',time: 1});
	  		   	   		
	    			    }else if(status ==1){//失败
	    			    	 layer.open({content: '<spring:message code="caozuoshibai"></spring:message>',skin: 'msg',time: 1});
	    	 		   	   		
	    			    }
	    			 }
	    			 });
		    }
		  });
		 
    	
    	
		 }
    /*选中触发事件*/
    $(function(){
        $("input[name='address']").each(function(){
            if($(this).is(':checked')) {
                $(".adressbottom").removeClass("on");
                $(this).parents(".adressbottom").addClass("on");
            }
        })
        $("input[name='address']").change(function() {
        	$a=$(this);
        	 $.ajax({
    			 url:'${pageContext.request.contextPath }/web/address/setdefaultaddress',
    			 async : false,
    			 data: {aId:$(this).val()},
    			 type : "POST", 
    			 success :function(result){
    			 var status=result.msg.status;
    			 var desc=result.msg.desc;
    			 if(status == 0){
    					$(".adressbottom").removeClass("on");
    					$a.parents(".adressbottom").addClass("on");
    					 layer.open({content: '<spring:message code="caozuochenggong"></spring:message>',skin: 'msg',time: 1});
    	 		   	   		
    					
    					//location.reload(true);
    			 }else if(status == 2){//没登录
    				 layer.open({content: '<spring:message code="weidenglu"></spring:message>',skin: 'msg',time: 1});
  		   	   		
    			    }else if(status ==1){//失败
    			    	 layer.open({content: '<spring:message code="caozuoshibai"></spring:message>',skin: 'msg',time: 1});
    	 		   	   		
    			    }
    			 }
    			 });
           
        });
    });
    function update(id){
     	location.href="${pageContext.request.contextPath }/api/address/viewddress/"+id;
	}
    function add(){
    	 $.ajax({
			 url:'${pageContext.request.contextPath }/web/address/chakanshuliang',
			 async : false,
			 type : "GET", 
			 success :function(result){
			 var status=result.msg.status;
			 var desc=result.msg.desc;
			 if(status == 0){
    			location.href="${pageContext.request.contextPath}/api/address/insertReciveAddress";
				 
			 }else if(status == 2){//没登录
				 layer.open({content: '<spring:message code="weidenglu"></spring:message>',skin: 'msg',time: 1});
		   	   		
			    }else if(status ==3){//失败
			    	 layer.open({content: '<spring:message code="zhinengtianjia3tiaojilu"></spring:message>',skin: 'msg',time: 1});
	 		   	   		
			    }
			 }
			 });
    	
    	
	}
    
</script>
</html>